package weatherapp;
import weatherapp.network.WeatherFetcher;
import weatherapp.parser.*;
import weatherapp.ui.*;

import java.util.Scanner;

public class WeatherApp {
    public static void main(String[] args) {
        try {
            Scanner scanner = new Scanner(System.in);
            System.out.print("请输入要查询的城市名（如 Beijing）：");
            String city = scanner.nextLine().trim();

            String apiKey = "c019e85e97416ca3270e16cefa595431";
            String url = "https://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + apiKey + "&units=metric";

            String json = WeatherFetcher.fetch(url);
            WeatherParser parser = new OpenWeatherMapParser();
            WeatherData data = parser.parse(json);

            new SimpleWeatherDisplay(data);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("发生错误：" + e.getMessage());
        }
    }
}
